// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: C Floor Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 63 : TYPE_CFLOOR

// Function declarations
reserve function CFloor_DebugDraw
reserve function CFloor_DebugSpawn

// Static Values

// Tables
public table CFloor_table0
	30, 22, 14, 6, 26, 18, 10, 2
end table

public table CFloor_table1
	22, 30, 26, 18, 6, 14, 10, 2
end table

function CFloor_DebugDraw
	DrawSprite(0)
end function


function CFloor_DebugSpawn
	CreateTempObject(TypeName[C Floor], 0, object.xpos, object.ypos)
	object[tempObjectPos].value2 = CFloor_table0
	GetBit(temp0, object.direction, 0)
	if temp0 == 0
		object[tempObjectPos].direction = FLIP_NONE
	else
		object[tempObjectPos].direction = FLIP_X
	end if
end function


event ObjectMain
	switch object.state
	case 1
		if object.value0 < 10
			object.value0++
		else
			temp5 = 0
			temp0 = 0
			temp3 = object.ypos
			temp3 -= 0x80000
			temp4 = 10
			while temp0 < 2
				temp1 = 0
				temp2 = object.xpos
				temp2 += 0x300000
				
				while temp1 < 7
					CreateTempObject(TypeName[C Floor], 1, temp2, temp3)
					object[tempObjectPos].state = 4
					if temp0 == 1
						temp4 = temp1
						temp4 %= 2
						if temp4 == 0
							object[tempObjectPos].propertyValue = 2
						end if
					end if
					GetTableValue(object[tempObjectPos].value1, temp5, object.value2)
					temp5++
					temp1++
					temp2 -= 0x100000
					temp4 += 4
				loop
				temp4 -= 26
				object.frame += 2
				temp0++
				temp3 += 0x100000
			loop
			PlaySfx(SfxName[Ledge Break L], 0)
			SetSfxAttributes(SfxName[Ledge Break L], -1, -100)
			PlaySfx(SfxName[Ledge Break R], 0)
			SetSfxAttributes(SfxName[Ledge Break R], -1, 100)
			object.value0 = 0
			object.state++
		end if
		break
	case 2
		if object.value0 < 20
			object.value0++
		else
			object.value0 = 0
			object.state++
		end if
		break
	case 4
		if object.value0 < object.value1
			object.value0++
		else
			object.value0 = 0
			object.state++
		end if
		break
	case 5
		object.ypos += object.yvel
		object.yvel += 0x4000
		if object.outOfBounds == 1
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
	if object.state < 4
		if object.outOfBounds == 1
			object.state = 0
			object.value0 = 0
			object.priority = PRIORITY_ACTIVE_BOUNDS
		end if
	end if
	if object.state < 3
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			if object[currentPlayer].yvel >= 0
				BoxCollisionTest(C_PLATFORM, object.entityPos, -56, -16, 56, 0, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object.state == 0
						object.state = 1
						object.priority = PRIORITY_ACTIVE
					end if
				end if
			end if
		next
	end if
end event


event ObjectDraw
	switch object.state
	case 0
	case 1
		DrawSprite(0)
		break
	case 4
	case 5
		DrawSprite(object.propertyValue)
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("MBZ/Objects.gif")
	SpriteFrame(-56, -16, 112, 32, 125, 330)
	SpriteFrame(-8, -8, 16, 16, 125, 330)
	SpriteFrame(-8, -8, 16, 16, 125, 346)
	foreach (TypeName[C Floor], arrayPos0, ALL_ENTITIES)
		GetBit(temp5, object[arrayPos0].propertyValue, 0)
		if temp5 == 0
			object[arrayPos0].value2 = CFloor_table0
		else
			object[arrayPos0].value2 = CFloor_table1
		end if
	next
	SetTableValue(TypeName[C Floor], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(CFloor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(CFloor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
